<%--
  Created by IntelliJ IDEA.
  User: jerry
  Date: 6/2/2020
  Time: 2:26 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">
    <title>Hello, world!</title>
</head>
<body class="text-center" data-gr-c-s-loaded="true">
<form class="form-signin" action="<%=request.getContextPath()%>/servlet/login" method="post">
    <img class="mb-4" src="images/bootstrap-solid.svg" alt="" width="72" height="72">
    <h1 class="h3 mb-3 font-weight-normal">请登录</h1>
    <%--做一个简单的判断，session中有msg的值，就显示在p标签中，没有就不显示        --%>

    <c:if test="${ sessionScope.msg != null}">
        <p style="color: red">${msg}</p>
    </c:if>

    <label for="inputUserName" class="sr-only">用户名</label>
    <input type="text" id="inputUserName" name="username" class="form-control" placeholder="输入用户名" required autofocus>
    <label for="inputPassword" class="sr-only">Password</label>
    <input type="password" id="inputPassword" name="pwd" class="form-control" placeholder="输入密码" required>
    <input type="text" id="tryCode" name="tryCode" class="form-control" placeholder="验证码" required="">
    <img id="imgTryCode" width="160px" height="50px" src="${pageContext.request.contextPath}/kaptcha/kaptcha.jpg">
    <a href="#" onclick="changeTryCode()"><span style="margin-left: 20px">看不清，换一张</span></a>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
    <p class="mt-5 mb-3 text-muted">&copy; 2020-2021</p>
</form>

<script type="text/javascript">
    function changeTryCode() {
        var img = document.getElementById("imgTryCode");

        // 重新给image的src属性赋值
        img.src = "${pageContext.request.contextPath}/kaptcha/kaptcha.jpg?d="+ new Date()*1
    }
</script>

</body>
</html>
